var member;
$(function(){
	member=getEntity("memberInfo");
	var type=$("#type").val();
	var redirect = GetQueryString("redirect");
	if(type!=null && type!=undefined){
		$.ajax({
			type:"post",
			url:rootPath+"/advert/getAdvertList",
			data:{'amount':4,'type':type},
			//dataType:"json",
			success:function(data){
				if(data.resultSuccess){
					var adverts=data.data;
					if(adverts!=null && adverts!=""){
						var str='';
						var str1='';
						var buttonStr='';
						var j = 0;
					//	alert(JSON.stringify(adverts))
						$("#list").empty();
						$("#buttons").empty();
						$.each(adverts,function(i,item){
							if(i==0){
								j=1;
							}
							str1+='<img src="'+item.img+'" alt="'+j+'"/>';
							if(i==0){
								buttonStr+='<span index="'+j+'" class="on"></span>'
							}else{
								buttonStr+='<span index="'+j+'"></span>'
							}
							j++;
							/* <img src="${ctx }/images/banner3.png" alt="1"/>
				            <img src="${ctx }/images/banner4.png" alt="2"/>
				            <img src="${ctx }/images/banner.png" alt="3"/>
				            <img src="${ctx }/images/banner2.png" alt="4"/>		
				            <img src="${ctx }/images/banner3.png" alt="1"/>
				            <img src="${ctx }/images/banner4.png" alt="2"/>*/
							/*str+='<img src="'+item.img+'" alt="1"/>';*/
						})
						str1+='<img src="'+adverts[0].img+'" alt="1"/>';
						$("#list").append(str1);
						$("#buttons").append(buttonStr);
					}
				}
			}
		});
	}
	$("#loginbtn").click(function(){
	//	var data = $("form").serialize();
		var formData = $("form").serialize();
		$.ajax({
			type:"post",
			url:rootPath+"/member/login",
			data:formData,
			//dataType:"json",
			success:function(data){
				if(data.resultSuccess){
					//alert(data.resultDesc)
					//alert(redirect)
					if(""==redirect){
						window.location.href=rootPath+"/";
					}else{
						window.location.href=rootPath + redirect;
					}
				}else{
					//$("#msg").text(data.resultDesc);
					$("#prompt").css('height','70px');
					$("#msg").text(data.resultDesc)
					$("#msg").css('display','block');
				}
			}
		})
	})
	if(member){
		/*<a href="${ctx }/member/loginPre">登录</a>
		<a href="${ctx }/register/registerPre">注册</a>*/
		$(".nav .r").prepend("<a href='"+rootPath+"/member/vip_safe_setting' class='me'>"+member.mName+"</a>");
		$(".me").append("<ul><li id='memberInfo'>个人中心</li><li id='exit'>退出</li></ul>");
	}else{
		$(".nav .r").prepend('<a href="'+rootPath+'/member/loginPre">登录</a><a href="'+rootPath+'/register/registerPre">注册</a>');
	}
	$(document).on('mouseover mouseout','.me',function(e){
		if(e.type == "mouseover"){
			$(this).find('ul').stop().slideDown();
			$(this).css('position','relative');
			$(this).find('ul').css('display','inline-block');
			$(this).find('ul').css('padding','5px')
			.css('position','absolute')
			.css('width','100px')
			.css('top','28px')
			.css('left','-8px')
			.css('color','#000')
			.css('padding','5px');
			$(this).find('li').css('margin','0')
			.css('line-height','20px')
			.css('text-align','center');
		}else if(e.type == "mouseout"){
			$(this).find('ul').stop().slideUp();
		}
	});
	$(document).on('click','#memberInfo',function(e){
		$.ajax({
			type:"post",
			url:rootPath+"/member/skip",
			//dataType:"json",
			success:function(data){
				if(data.resultSuccess){
					window.location.href=rootPath+"/member/vip_safe_setting";
				}
			}
		})
	})
	$(document).on('click','#exit',function(e){
		$.ajax({
			type:"post",
			url:rootPath+"/member/exit",
			//dataType:"json",
			success:function(data){
				if(data.resultSuccess){
					window.location.href=rootPath+"/member/loginPre";
				}
			}
		})
	})
	 $("body").keydown(function() {
         if (event.keyCode == "13") {//keyCode=13是回车键
             $('#loginbtn').click();
         }
     });

})